import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class test01 {
    public void JDBCupdate() throws ClassNotFoundException, SQLException {
        //1. 注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2. 获取连接
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://127.0.0.1:3306/test01?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true",
                "jvnanji",
                "qaq123456");

        //3.获取sql语句的执行对象
        Statement sta = connection.createStatement();

        //4.执行sql语句
        String sql = "update user set username='nanji' where id=1";
        int count = sta.executeUpdate(sql);

        //5.释放资源
        sta.close();
        connection.close();
    }
}
